package com.business_clean.app.weight.dialog;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.business_clean.R;
import com.business_clean.app.App;
import com.lxj.xpopup.core.BottomPopupView;
import com.otaliastudios.cameraview.controls.Flash;

public class CameraSettingDialog extends BottomPopupView {


    private CameraSettingDialogListener listener;

    private TextView tvUserName;
    private TextView tvCancel;

    private ImageView ivFlash, ivChange, ivSetting, ivUser;

    private int flash;

    public CameraSettingDialog(@NonNull Context context, int flash, CameraSettingDialogListener listener) {
        super(context);
        this.flash = flash;
        this.listener = listener;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_camera_setting;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        tvUserName = findViewById(R.id.tv_dialog_camera_user);
        ivFlash = findViewById(R.id.iv_dialog_camera_setting_flash);
        ivChange = findViewById(R.id.iv_dialog_camera_setting_change);
        ivSetting = findViewById(R.id.iv_dialog_camera_setting);
        ivUser = findViewById(R.id.iv_dialog_camera_user);
        tvCancel = findViewById(R.id.tv_dialog_camera_cancel);

        switch (flash) {
            case 1:
                ivFlash.setImageResource(R.mipmap.icon_camera_flash_open);
                break;
            case 2:
                ivFlash.setImageResource(R.mipmap.icon_camera_auto_flash);
                break;
            case 0:
                ivFlash.setImageResource(R.mipmap.icon_camera_flash);
                break;
        }

        tvUserName.setText("您好，" + App.appViewModelInstance.getUserInfo().getValue().getUser().getUser_name());

        if (tvCancel != null) {
            tvCancel.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
        }
        onBindViewClick();
    }

    private void onBindViewClick() {
        ivFlash.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.clickChange(1);
                dismiss();
            }
        });

        ivChange.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.clickChange(2);
                dismiss();
            }
        });

        ivSetting.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.clickChange(3);
                dismiss();
            }
        });

        ivUser.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.clickChange(4);
                dismiss();
            }
        });


    }


    public interface CameraSettingDialogListener {
        void clickChange(int how);
    }

}
